<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>vue-boot 权限管理</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../static/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../static/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../static/css/style.css">
    <link rel="stylesheet" href="../static/plugins/pageination/zpageNav.css">
    <script src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../static/plugins/bootstrap/js/bootstrap.min.js"></script>
</head>

<body class="hold-transition skin-red sidebar-mini">

<div id="app">
    <div class="box-header with-border" style="height: 64.5px;line-height: 54px;">
        <h3 class="box-title">权限管理</h3>
    </div>
    <div class="box-body">
        <!-- 数据表格 -->
        <div class="table-box">
            <!--工具栏-->
            <div class="pull-left">
                <div class="form-group form-inline">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i
                                class="fa fa-refresh"></i> 刷新
                        </button>
                    </div>
                    <div class="box-tools pull-right">
                        <div class="has-feedback" style="margin-left: 750px; font-size: 16px">
                            权限查询: <input type="text" v-model="key" class="form-control">
                            <input class="btn btn-default" type="button" @click="pageHandler(1)" value="查询">
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-tools pull-right">
                <div class="has-feedback"></div>
            </div>
            <!--数据列表-->
            <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                <thead>
                <tr>
                    <th class="sorting_asc">ID</th>
                    <th class="sorting_asc">用户名</th>
                    <th class="sorting_asc">权限身份</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="authorityItem in AuthorityList">
                    <td>{{authorityItem.id}}</td>
                    <td>{{authorityItem.username}}</td>
                    <td >{{authorityItem.authority}}</td>
                    <td class="text-center">
                        <button type="button" @click="changeAuth(1,authorityItem.id)"  style="outline:none;border-radius:4px;font-size:2px;width:100px;height:22px;background-color: red;color: white;border: none">
                            超级管理员
                        </button>
                        <button type="button" @click="changeAuth(2,authorityItem.id)" style="outline:none;border-radius:4px;font-size:2px;width:100px;height:22px;background-color: hotpink;color: white;border: none">
                            部门管理员
                        </button>

                        <button type="button" @click="changeAuth(3,authorityItem.id)"style="outline:none;border-radius:4px;font-size:2px;width:100px;height:22px;background-color: forestgreen;color: white;border: none">
                            普通员工
                        </button>
                    </td>
                </tr>

                </tbody>

            </table>

        </div>
    </div>
    <!--分页-->
    <zpagenav v-bind:page="page" v-bind:page-size="pageSize" v-bind:total="total"
              v-bind:max-page="maxPage" v-on:pagehandler="pageHandler">
    </zpagenav>
    </div>

</body>


<script src="../static/plugins/vue/vuejs-2.5.16.js"></script>
<script src="../static/plugins/vue/axios-0.18.0.js"></script>
<script src="../static/plugins/vue/qs.js"></script>
<script src="../static/plugins/pageination/zpageNav.js"></script>
<script>
    new Vue({
        el: "#app",
        data:{
            page:1,
            pageSize:5,
            total: 0,
            key:'',
            AuthorityList:[],

        },
        methods:{
            pageHandler: function (page) {
                var _this = this;
                this.page = page;
                axios.post("/auth/search?page=" + page + "&size=" + this.pageSize + "&key=" + this.key)
                    .then(function (response) {
                        _this.AuthorityList = response.data.data.records;
                        _this.total = response.data.data.total;
                        _this.pageSize = response.data.data.size;
                        console.log(response);
                    }).catch(function (reason) {
                    console.log(reason);
                })
            },
            changeAuth: function (authId,id) {
                var _this = this;
                axios.post("/auth/changeAuth?authId=" + authId+"&id="+id).then(function (response) {
                    if (response.data.code == 200) {
                        _this.pageHandler(_this.page);
                        window.alert(response.data.msg);
                    } else {
                        window.alert(response.data.msg);
                    }
                }).catch(function (reason) {
                    console.log(reason);
                });

            }

        },
        created: function () {
            this.pageHandler(1);
        }
    })


</script>


</html>